/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.h2demo;

import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.h2.tools.Server;

/**
 * "-tcpPort", "9128", "-tcpAllowOthers"
 * String databaseUrl = "jdbc:h2:tcp://localhost:9128/mem:mydb;AUTO_RECONNECT=TRUE";
 * @author Administrator
 */
public class H2ORMConn {
    
    public static ConnectionSource getConn (Server server){
//        if(server==null){            
//            try {
//                server = Server.createTcpServer().start();
//            } catch (SQLException ex) {
//                Logger.getLogger(H2ORMConn.class.getName()).log(Level.SEVERE, null, ex);
//            }
//        }
        
         App.p("url:"+App.JDBC_URL);
            
        try {
            return new JdbcConnectionSource(App.JDBC_URL,App.USER,App.PASSWORD);
        } catch (SQLException ex) {
            Logger.getLogger(H2ORMConn.class.getName()).log(Level.SEVERE, null, ex);
        }
        
       return null;
        
    }
    
    public static void closeCon(ConnectionSource c){
        if(c!=null){
            try {
                c.close();
            } catch (IOException ex) {
                Logger.getLogger(H2ORMConn.class.getName()).log(Level.SEVERE, null, ex);
            }
             
        }
    }
}
